package com.ff.ticket.repository;

import com.ff.ticket.domain.Show;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface ShowRepository extends JpaRepository<Show,String> {

    //根据id查找演出
    @Query(value = "SELECT * FROM show a  where a.id=?1", nativeQuery = true)
    public Show findShowById(int id);


    //根据状态查找演出
    @Query(value = "SELECT * FROM show a  where a.show_status=?1", nativeQuery = true)
    public List<Show> findShowsByStatus(String status);

    //根据状态和模糊搜索条件查找演出
    @Query(value = "SELECT * FROM show a  where a.show_status=:status and (a.id like CONCAT('%',:tag,'%') or a.show_name like CONCAT('%',:tag,'%') " +
            "or a.show_type like CONCAT('%',:tag,'%') or a.show_field like CONCAT('%',:tag,'%') or a.showAddress like CONCAT('%',:tag,'%') " +
            "or a.show_organiser like CONCAT('%',:tag,'%') )", nativeQuery = true)
    public List<Show> findShowsByStatusAndTag(@Param("status")String status,@Param("tag")String tag);

    //根据状态和模糊搜索条件查找演出
    @Query(value = "SELECT * FROM show a  where a.id like CONCAT('%',:tag,'%') or a.show_name like CONCAT('%',:tag,'%') " +
            "or a.show_type like CONCAT('%',:tag,'%') or a.show_field like CONCAT('%',:tag,'%') or a.showAddress like CONCAT('%',:tag,'%') " +
            "or a.show_organiser like CONCAT('%',:tag,'%')", nativeQuery = true)
    public List<Show> findShowsByTag(@Param("tag")String tag);


}
